﻿@model Retete.ViewModels.ReceptieViewModel
@{
    ViewBag.Title = "Receptii";
}

<script type="text/javascript">
    function submitOnEnter() {
        if (event.keyCode == "13") {
            FinalizareAdaugareProdusInventar.value = true;
            form.submit();
        }
    }
    function terminare() {
        FinalizareAdaugareProdusInventar.value = true;
        form.submit();
    }
</script>

@using (Html.BeginForm(null, null, FormMethod.Post, new { id = "form", name = "form" }))
{
    <table style="width: 100%">
        <tr>
            <td style="width: 190px; vertical-align: top; border-right-style: dashed; border-right-color: #CFCFCF; border-right-width: 1px;">
                <fieldset>
                    <legend>Activitati</legend>

                    <p class="toolbox"><a href="javascript:terminare()">Accepta</a></p>
                    <p class="toolbox">@Html.ActionLink("Renunta", "Index")</p>
                </fieldset>
            </td>
            <td style="vertical-align: top;">
                @Html.ValidationSummary(false)
                @Html.HiddenFor(model => model.IDProdusSters)
                @Html.HiddenFor(model => model.FocusProdusNou)
                @Html.HiddenFor(model => model.FinalizareAdaugareProdusInventar)

                <fieldset style="display: none">
                    <legend>Detalii receptie</legend>

                    <p>
                        @Html.LabelFor(model => model.Receptie.Numar, "Numar si data")
                        @Html.TextBoxFor(model => model.Receptie.Numar, new { @style = "width: 145px" })
                        @Html.TextBoxFor(model => model.Receptie.Data, new { @style = "width: 146px" })
                    </p>

                    <p>
                        @Html.LabelFor(model => model.Receptie.TipDocumentLivrare, "Tip si numar livrare")
                        @Html.DropDownListFor(model => model.Receptie.TipDocumentLivrare, new SelectList(new string[] { "Factura", "Borderou achizitie" }), new { @style = "width: 151px" })
                        @Html.TextBoxFor(model => model.Receptie.NumarDocumentLivrare, new { @style = "width: 146px" })
                    </p>

                    <p>
                        @Html.LabelFor(model => model.Receptie.Tva, "TVA")
                        @Html.TextBoxFor(model => model.Receptie.Tva)
                    </p>
                </fieldset>
    
                <fieldset style="display: none">
                    <legend>Detalii furnizor</legend>

                    <p>
                        @Html.LabelFor(model => model.Receptie.FurnizorNume, "Furnizor")
                        @Html.EditorFor(model => model.Receptie.FurnizorNume)
                    </p>

                    <p>
                        @Html.LabelFor(model => model.Receptie.FurnizorAdresa, "Adresa si judet")
                        @Html.TextBoxFor(model => model.Receptie.FurnizorAdresa, new { style = "width: 200px" })
                        @Html.TextBoxFor(model => model.Receptie.FurnizorJudet, new { style = "width: 91px" })
                    </p>
        
                    <p>
                        @Html.LabelFor(model => model.Receptie.FurnizorCodFiscal, "CUI si cod reg. comert")
                        @Html.TextBoxFor(model => model.Receptie.FurnizorCodFiscal, new { style = "width: 145px" })
                        @Html.TextBoxFor(model => model.Receptie.FurnizorCodRegistruComert, new { style = "width: 146px" })
                    </p>

                    <p>
                        @Html.LabelFor(model => model.Receptie.FurnizorCont, "Cont si banca")
                        @Html.TextBoxFor(model => model.Receptie.FurnizorCont, new { style = "width: 145px" })
                        @Html.TextBoxFor(model => model.Receptie.FurnizorBanca, new { style = "width: 146px" })
                    </p>
                </fieldset>

                <fieldset>
                    <legend>Adaugare produs nou in inventar</legend>

                    <p>
                        @Html.LabelFor(model => model.ProdusNouInventarCod, "Cod si nume")
                        @Html.TextBoxFor(model => model.ProdusNouInventarCod, new { style = "width: 80px;", placeholder = Model.CodUltimulProdus })
                        @Html.TextBoxFor(model => model.ProdusNouInventarNume, new { style = "width: 211px;" })
                    </p>

                    <p>
                        @Html.LabelFor(model => model.ProdusNouInventarCategorie, "UM si categorie")
                        @Html.TextBoxFor(model => model.ProdusNouInventarUnitateMasura, new { style = "width: 80px;" })
                        @Html.TextBoxFor(model => model.ProdusNouInventarCategorie, new { style = "width: 211px;", onkeydown="submitOnEnter()" })
                    </p>
                </fieldset>
    
                <fieldset style="display: none">
                    <legend>Produse cumparate (pret de achizitie fara TVA, pret de vanzare cu TVA)</legend>
            
                    <table class="grid">
                        <thead>
                            <tr>
                                <th style="width: 16px"></th>
                                <td style="width: 70px">Cod</td>
                                <th>Produs</th>
                                <th style="width: 60px">Gramaj</th>
                                <th style="width: 40px">Cant.</th>
                                <th style="width: 40px">UM</th>
                                <th style="width: 40px">TVA</th>
                                <th style="width: 70px">Cumparare</th>
                                <th style="width: 70px">Valoare</th>
                                <th style="width: 70px">Val. TVA</th>
                                <th style="width: 70px">Val. cu TVA</th>
                                <th style="width: 70px">Vanzare</th>
                            </tr>
                        </thead>
        
                        <tbody id="tableBody">
                            <tr class="insertionRow">
                                <td></td>
                                <td id="ProdusNou_Cod"></td>
                                <td>
                                    @Html.TextBoxFor(model => model.ProdusNouNume, new { autocomplete = "off" })
                                    @Html.HiddenFor(model => model.ProdusNouID)
                                    @Html.HiddenFor(model => model.ProdusNouCod)
                                </td>
                                <td>@Html.TextBoxFor(model => model.ProdusNouGramaj, new { autocomplete = "off" })</td>
                                <td>@Html.TextBoxFor(model => model.ProdusNouCantitate, new { autocomplete = "off" })</td>
                                <td id="UnitateMasura"></td>
                                <td>@Html.CheckBoxFor(model => model.ProdusNouTVA, new { style = "height: 13px;" })</td>
                                <td>@Html.TextBoxFor(model => model.ProdusNouPret, new { autocomplete = "off" })</td>
                                <td></td>
                                <td></td>
                                <td id="ValoareCuTva"></td>
                                <td>@Html.TextBoxFor(model => model.ProdusNouPretVanzare, new { autocomplete = "off", onkeydown = "return submitOnEnter()" })</td>
                            </tr>

                            @if (@Model.Produse != null)
                            {
                                for (int i = 0; i < Model.Produse.Count; i++)
                                {
                                    <tr>
                                        <td>
                                            <img src="@Url.Content("~/Content/Images/Delete.png")" alt="Sterge" style="height: 12px; cursor: pointer;" onclick="stergeInregistrare(@Model.Produse[i].ID)" />
                                            @Html.HiddenFor(element => element.Produse[i].ID)
                                            @Html.HiddenFor(element => element.Produse[i].Receptie.Tva)
                                        </td>
                                        <td>
                                            @Html.DisplayTextFor(element => element.Produse[i].Produs.Cod)
                                            @Html.HiddenFor(element => element.Produse[i].Produs.Cod)
                                            @Html.HiddenFor(element => element.Produse[i].Produs.Categorie)
                                        </td>
                                        <td>
                                            @Html.DisplayTextFor(element => element.Produse[i].Produs.Nume)
                                            @Html.HiddenFor(element => element.Produse[i].Produs.Nume)
                                            @Html.HiddenFor(element => element.Produse[i].IDProdus)
                                        </td>
                                        <td>
                                            @Model.Produse[i].Gramaj.ToString("0.00")
                                            @Html.HiddenFor(element => element.Produse[i].Gramaj)
                                        </td>
                                        <td class="insertionCell">@Html.TextBoxFor(element => element.Produse[i].Cantitate)</td>
                                        <td>
                                            @Html.DisplayTextFor(element => element.Produse[i].Produs.UnitateMasura)
                                            @Html.HiddenFor(element => element.Produse[i].Produs.UnitateMasura)
                                        </td>
                                        <td class="checkBoxCell">@Html.CheckBoxFor(element => element.Produse[i].AdmiteTVA, new { style = "width: 20px;" })</td>
                                        <td class="insertionCell">@Html.TextBoxFor(element => element.Produse[i].PretCumparare)</td>
                                        <td>
                                            @Model.Produse[i].Valoare.ToString("0.00")
                                            @Html.HiddenFor(element => element.Produse[i].Valoare)
                                        </td>
                                        <td>
                                            @Model.Produse[i].ValoareTVA.ToString("0.00")
                                            @Html.HiddenFor(element => element.Produse[i].ValoareTVA)
                                        </td>
                                        <td>
                                            @Model.Produse[i].ValoareCuTVA.ToString("0.00")
                                            @Html.HiddenFor(element => element.Produse[i].ValoareCuTVA)
                                        </td>
                                        <td class="insertionCell">@Html.TextBoxFor(element => element.Produse[i].PretVanzare)</td>
                                    </tr>
                                }
                                
                                <tr class="totals">
                                    <td></td>
                                    <td></td>
                                    <td>Total:</td>
                                    <td></td>
                                    <td></td>
                                    <td></td>
                                    <td></td>
                                    <td></td>
                                    <td class="insertionCell">@Html.TextBoxFor(element => element.TotalValoare)</td>
                                    <td class="insertionCell">@Html.TextBoxFor(element => element.TotalValoareTVA)</td>
                                    <td class="insertionCell">@Html.TextBoxFor(element => element.TotalValoareCuTVA)</td>
                                    <td></td>
                                </tr>
                            }
                        </tbody>
                    </table>
                </fieldset>
            </td>
        </tr>
    </table>
}